/**
 * Control de objeto de juego a partir de cuerpo de box2d.
 * @constructor
 * @param {GameObject} gameObject - objeto de juego a manipular.
 * @param {Box2D.Dynamics.b2Body} box2dbody - cuerpo de box2d de control.
 * @param {Box2DSys} box2dsys - sistema de box2d..
 */
Box2DController = function(gameObject, box2dbody, box2dsys , jumpPower) {
    Controller.call(this, gameObject);
    this.box2dbody = box2dbody;
    this.box2dsys = box2dsys;
    this.jumpPower = jumpPower || 150 ;
};

Box2DController.prototype = Controller.prototype;

Box2DController.prototype.run = function() {
    var body = this.box2dbody;

    var sidePower = 2;
    var speedLimit = 20;
    var box2dsys = this.box2dsys;

    if (input.right) {
        if (body.GetLinearVelocity().x < speedLimit)
            box2dsys.applyImpulse(body, 0, sidePower);
    }
    if (input.left) {
        if (body.GetLinearVelocity().x > -speedLimit)
            box2dsys.applyImpulse(body, 0, -sidePower);
    }

    if (input.up) {
        if (body.GetLinearVelocity().y == 0)
            box2dsys.applyImpulse(body, -90, this.jumpPower);
    }
    
    if(this.gameObject)
        this.updatePos();
};
//run

Box2DController.prototype.updatePos = function() {
    var body = this.box2dbody;
    var go = this.gameObject;
    var b2dpos = body.GetPosition();

    if (this.box2dsys) {
        var xx = this.box2dsys.mtp(b2dpos.x);
        var yy = this.box2dsys.mtp(b2dpos.y);
        go.setPos(xx,yy);
    } else {
        go.setPos(go.x,go.y);
    }
};//updatePos
